HA$PBExportHeader$u_cst_treeview.sru
forward
global type u_cst_treeview from userobject
end type
type uo_toolbar from u_cst_toolbarstrip within u_cst_treeview
end type
type sle_1 from singlelineedit within u_cst_treeview
end type
type pb_1 from picturebutton within u_cst_treeview
end type
type tv_main from treeview within u_cst_treeview
end type
end forward

global type u_cst_treeview from userobject
integer width = 713
integer height = 2356
long backcolor = 67108864
string text = "none"
long tabtextcolor = 33554432
long picturemaskcolor = 536870912
event resize pbm_size
uo_toolbar uo_toolbar
sle_1 sle_1
pb_1 pb_1
tv_main tv_main
end type
global u_cst_treeview u_cst_treeview

type variables
integer il_root , il_nodo, il_expa = 0

window iw_parent
end variables

forward prototypes
public function integer of_getwindow ()
public subroutine of_loadmenu (string as_modulo)
public function boolean of_has_children (ref datastore ads_data, string as_grupo)
end prototypes

event resize;//tv_main.width  = newwidth - 10
uo_toolbar.width  = newwidth - 10
////rr_1.width  = width -30
////sle_1. width  = width - 50
//tv_main.height = newheight //- ( uo_toolbar.height +100)
//
//
//tv_main.move( 4, uo_toolbar.height+4)
//tv_main.height =0  //newheight  - (uo_toolbar.height+1000) 
//tv_main.resize(newwidth, tv_main.height - (uo_toolbar.height+100) )
//tv_main.resize(0, 0)

end event

public function integer of_getwindow ();PowerObject	lpo_parent
Window lw_window

// loop thru parents until a window is found
lpo_parent = GetParent()
Do While lpo_parent.TypeOf() <> Window! and IsValid(lpo_parent)
	lpo_parent = lpo_parent.GetParent()
Loop

// set return to the window or null if not found
If IsValid (lpo_parent) Then
	lw_window = lpo_parent
Else
	SetNull(lw_window)
End If

iw_parent = lw_window

RETURN 1
end function

public subroutine of_loadmenu (string as_modulo);//gds_gmenu = Create DataStore
//gds_gmenu.DataObject = 'd_mgmenu_idmodulo'
//gds_gmenu.settransobject( sqlca)
//gds_gmenu.retrieve(as_modulo)

gds_menu = Create DataStore
gds_menu.DataObject ='d_menu'// "d_mainmenu"
gds_menu.settransobject( sqlca)
gds_menu.retrieve(gs_iduser)


gds_modulo = Create DataStore
gds_modulo.DataObject ='d_mmodulo_muser_grid_iduser'// "d_mainmenu"
gds_modulo.settransobject( sqlca)
gds_modulo.retrieve(gs_iduser) 

commit;

end subroutine

public function boolean of_has_children (ref datastore ads_data, string as_grupo);Integer li_Rows

li_Rows = ads_Data.RowCount()

If ads_Data.Find('idGmenu = "' + as_grupo+ '"', 1, li_Rows) <= 0 Then
	Return False
Else
	Return True
End If
end function

on u_cst_treeview.create
this.uo_toolbar=create uo_toolbar
this.sle_1=create sle_1
this.pb_1=create pb_1
this.tv_main=create tv_main
this.Control[]={this.uo_toolbar,&
this.sle_1,&
this.pb_1,&
this.tv_main}
end on

on u_cst_treeview.destroy
destroy(this.uo_toolbar)
destroy(this.sle_1)
destroy(this.pb_1)
destroy(this.tv_main)
end on

event constructor;of_getwindow( )
il_nodo =1

end event

type uo_toolbar from u_cst_toolbarstrip within u_cst_treeview
integer x = 5
integer y = 4
integer width = 690
integer height = 116
integer taborder = 30
end type

on uo_toolbar.destroy
call u_cst_toolbarstrip::destroy
end on

event constructor;call super::constructor;this.of_AddItem('Login', gs_unidad+'\IMG\ICO\Login.ico','Login')
this.of_AddItem('Refrescar',gs_unidad+'\IMG\ICO\Refresh.ico','Refrescar Menu')
this.of_AddItem('Contraer','TreeView!','Contraer Menu')

//this.of_setsize( this.Medium)

//this.of_addimage( /*string as_image */)
//this.of_setenabled('Grabar', false)

//this.of_AddItem('Cancelar', 'Undo!')
//this.of_AddItem('Salir', 'Exit!')
this.of_DisplayText(true)

uo_toolbar.of_SetTheme('Blue')

end event

event ue_buttonclicked;call super::ue_buttonclicked;choose case UPPER(as_button)
//	case 'CONTRAER'
////	tv_main.
//	tv_main.collapseitem(1)
	case 'REFRESCAR' 
		of_loadmenu('')
		il_expa = 0
		tv_main.event ue_gmenu()
		//tv_main.DeleteItem(il_nodo)
		//tv_main.ExpandItem ( il_nodo ) 
	case 'LOGIN'
		OPEN(W_LOGON)
	case 'CONTRAER'
		il_expa = 1
		tv_main.event ue_gmenu()
End choose
end event

type sle_1 from singlelineedit within u_cst_treeview
boolean visible = false
integer x = 681
integer width = 334
integer height = 92
integer taborder = 20
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "none"
borderstyle borderstyle = stylelowered!
end type

type pb_1 from picturebutton within u_cst_treeview
boolean visible = false
integer x = 59
integer y = 28
integer width = 101
integer height = 88
integer taborder = 10
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
boolean originalsize = true
string picturename = "Find!"
alignment htextalign = left!
end type

type tv_main from treeview within u_cst_treeview
event ue_gmenu ( )
event ue_expand_all ( )
event ue_collapse_all ( )
integer y = 112
integer width = 695
integer height = 548
integer taborder = 10
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string pointer = "HyperLink!"
long textcolor = 33554432
borderstyle borderstyle = stylelowered!
string picturename[] = {"..\\IMG\ICO\Java.ico","CreateIndex!","UserObject1!","ListBox!"}
long picturemaskcolor = 536870912
string statepicturename[] = {""}
long statepicturemaskcolor = 536870912
end type

event ue_gmenu();String			ls_superTmp,	ls_modulo,ls_idGMenu,ls_cadena,ls_Sub, ls_Super,ls_grupo,ls_grupo_ant,ls_nivel , ls_nivelSuper,ls_ImgModulo
Integer			li_sw,	li_Categories, li_Sub, li_Cnt,li_fila,li_nivel,li_Picture
Long					ll_Super, ll_item,ll_item2,ll_Modulo,il_root1
TreeViewItem	ltvi_Item
SetPointer(HourGlass!)
tv_main.DeleteItem(0)

ltvi_Item.Label = "RECURSOS Y APLICACIONES"
ltvi_Item.Data = ""
ltvi_Item.PictureIndex = 1
ltvi_Item.SelectedPictureIndex =1  // ltvi_Item.PictureIndex
ltvi_Item.Children = true
il_root = tv_main.InsertItemLast (0, ltvi_Item)
gds_gmenu = Create DataStore 
gds_gmenu.DataObject = 'd_gmenu_grid_idmodulo'
gds_gmenu.settransobject( sqlca)
//gds_gmenu.retrieve()
string ls_Category
FOR li_fila = 1 to  gds_modulo.RowCount()
	
	ltvi_Item.Label = gds_modulo.object.mmodulo_tdesc[li_fila]
	ltvi_Item.Data  = gds_modulo.object.idmodulo[li_fila]
	ls_ImgModulo = gds_modulo.Object.timg[li_fila]
	if left(trim(ls_ImgModulo),1) = '\' then	
		ls_ImgModulo = gs_unidad+ls_ImgModulo		
	end if
	li_Picture = this.AddPicture(ls_ImgModulo)
	ltvi_Item.PictureIndex =li_Picture
	ltvi_Item.SelectedPictureIndex =ltvi_Item.PictureIndex
	il_root1 = tv_main.InsertItemLast(il_root, ltvi_Item)
	ltvi_Item.Children = True
	ls_modulo = gds_modulo.object.idmodulo[li_fila] 
	//cargar los menus del modulo
	gds_gmenu.retrieve(ls_modulo,gs_iduser )
	li_Categories =  gds_gmenu.RowCount()
	For li_Cnt = 1 To li_Categories
		ls_Category = gds_gmenu.Object.tdesc[li_Cnt]
		ls_idGMenu  =  gds_gmenu.Object.idGMenu[li_Cnt]  //ID GRUPO MENU
		li_Sub = Pos(ls_Category, " - ")
		if li_Sub > 0 Then
			ls_Sub = Mid(ls_Category, (li_Sub + 3))
			
			ls_Super = Left(ls_Category, (li_Sub - 1))
			li_sw = 0
			If ll_Super = 0  Then
				ls_Super = Left(ls_Category, (li_Sub - 1))
				ltvi_Item.Label = ls_Super
				ls_superTmp  = ls_Super
				li_sw = 1
				ltvi_Item.Data ='G'+ls_Super// ls_idGMenu
				ltvi_Item.PictureIndex =2//li_Cnt
				ltvi_Item.SelectedPictureIndex = 2//ltvi_Item.PictureIndex
				ltvi_Item.Children = True
				ll_Super = This.InsertItemLast(il_root1, ltvi_Item)
				//ll_Super = This.InsertItemLast(ll_Modulo, ltvi_Item) 
			End If
			If ls_superTmp <> ls_Super and  len(ls_superTmp) > 0 and li_sw <> 1  Then
				ls_Super = Left(ls_Category, (li_Sub - 1))
				ltvi_Item.Label = ls_Super
				ls_superTmp  = ls_Super
				ltvi_Item.Data ='G'+ls_Super// ls_idGMenu
				ltvi_Item.PictureIndex =2//li_Cnt
				ltvi_Item.SelectedPictureIndex = 2//ltvi_Item.PictureIndex
				ltvi_Item.Children = True
				ll_Super = This.InsertItemLast(il_root1, ltvi_Item)
			
				//ll_Super = This.InsertItemLast(ll_Modulo, ltvi_Item) 
			End If
			
			ltvi_Item.Label = ls_Sub
			ltvi_Item.Data = ls_idGMenu
			
		Else
			ll_Super = 0
			ltvi_Item.Label = ls_Category
			ltvi_Item.Data = ls_idGMenu
		End If
		
		ltvi_Item.PictureIndex = 3//li_Cnt
		ltvi_Item.SelectedPictureIndex = ltvi_Item.PictureIndex
		If of_has_children(gds_menu, ls_idGMenu) Then
			ltvi_Item.Children = True
		Else
			ltvi_Item.Children = False
		End If
		 
		If ll_super = 0 Then
			ll_item = This.InsertItemLast(il_root1, ltvi_Item)
		Else
			ll_item = This.InsertItemLast(ll_Super, ltvi_Item)
		End If
		
	Next

//	For li_Cnt = 1 To li_Categories
//		ls_idGMenu  =  string(gds_gmenu.Object.idGMenu[li_Cnt])//ID GRUPO MENU
//		ls_Grupo     =  gds_gmenu.Object.tDesc[li_Cnt] //DESC GRUP MENU
//		ls_Nivel       = TRIM(gds_gmenu.Object.idNivel[li_Cnt] )//NIVEL
//		
//		ltvi_Item.Label = ls_grupo
//		ltvi_Item.Data  = ls_idGMenu
//		ltvi_Item.PictureIndex = 3 //li_Cnt
//		ltvi_Item.SelectedPictureIndex =3// ltvi_Item.PictureIndex
//		If of_has_children(gds_menu, ls_idGMenu) Then
//			ltvi_Item.Children = True
//		Else
//			ltvi_Item.Children = False
//		End If
//		IF len(ls_nivel) = 3 THEN
//			ltvi_Item.Children = True
//			ll_Super = tv_main.InsertItemLast(ll_Modulo, ltvi_Item)
//		ELSEIF len(ls_nivel) = 4 THEN
//			ll_item = tv_main.InsertItemLast(ll_Super, ltvi_Item)
//		ELSEIF len(ls_nivel) = 5 THEN
//			ll_item2 =tv_main.InsertItemLast(ll_item, ltvi_Item)
//		ELSEIF len(ls_nivel) = 6 THEN
//			tv_main.InsertItemLast(ll_item2, ltvi_Item)
//		END IF
//	Next
NEXT
THIS.ExpandItem ( il_nodo ) 
if il_expa = 0 then Event ue_expand_all()

end event

event ue_expand_all();SetPointer(HourGlass!)

this.SetReDraw ( False ) 

this.ExpandAll ( il_root ) 



this.SetFirstVisible ( il_root )

this.SetReDraw ( True )

end event

event ue_collapse_all();SetPointer(HourGlass!)

This.CollapseItem(il_root)
end event

event itempopulate;String				ls_Filter
Integer				li_Cnt, li_Examples,li_visible,li_enabled,li_Picture
String				ls_Category,ls_img
TreeViewItem	ltvi_New, ltvi_Parent

This.GetItem(handle, ltvi_Parent)

ls_Category = ltvi_Parent.Data

li_Examples = gds_menu.RowCount()
li_Cnt = gds_menu.Find("idGmenu = '" + ls_Category + "'", 1, li_Examples)
Do While li_Cnt > 0
///	li_  = gds_mainmenu.Object.cvisible[li_Cnt]
	ltvi_New.Label = gds_menu.Object.tDesc[li_Cnt]
	ltvi_New.Data  = gds_menu.Object.idMenu[li_Cnt]
	ls_img = gds_menu.Object.tPictureName[li_Cnt]
	if left(trim(ls_img),1)='\' then ls_img = gs_unidad+ls_img
	li_Picture = this.AddPicture(ls_img)
	ltvi_New.PictureIndex = li_Picture
	ltvi_New.Children = False
//tvi_New.PictureIndex = li_Picture
	ltvi_New.SelectedPictureIndex = ltvi_New.PictureIndex
//	If ids_Examples.Object.version[li_Cnt] = "8.0" Then
//		ltvi_New.PictureIndex = 29
//	ElseIf ids_Examples.Object.new[li_Cnt] = 1 Then
//		ltvi_New.PictureIndex = 27
//	ElseIf ids_Examples.Object.enhanced[li_Cnt] = 1 Then
//		ltvi_New.PictureIndex = 28
//	Else
//	ltvi_New.PictureIndex =5
//	End If
	//ltvi_New.SelectedPictureIndex =1// ltvi_New.PictureIndex
	This.InsertItemLast(handle, ltvi_New)
	If li_Cnt < li_Examples Then
		li_Cnt = gds_menu.Find("idGmenu = '" + ls_Category + "'", (li_Cnt + 1), li_Examples)
	Else
		li_Cnt = 0
	End If
Loop

end event

event doubleclicked;String				ls_Window,ls_userobject,ls_menu,ls_data,ls_titulo,ls_rutaMain
long ll_menu
integer li_menu
TreeViewItem	ltvi_Current
//m_main_rmb		lm_RMB

If handle > 0 Then 
	if GetItem(handle, ltvi_Current) < 0 then return
	
	this.SelectItem ( handle ) 
	ls_menu =UPPER(string(ltvi_Current.Data))
	if left(ls_menu,1) = 'G' OR left(ls_menu,2)  = 'MO' OR LEN(ls_menu) = 0 then return
	ls_titulo  = ltvi_Current.label
	
	//f_msj(ls_menu +' '+ ls_titulo,4)
	SetPointer(HourGlass!)
	//iw_parent.Dynamic post of_run_userobject(ls_menu)
	iw_parent.Dynamic post of_run_userobject(ls_menu)
	SetPointer(Arrow!)
End If

end event

event selectionchanged;//il_nodo = newhandle
//
//f_msj(string(il_nodo),4)
//
end event

event clicked;
//long ll_tvi
//
//il_nodo =handle //is.FindItem(CurrentTreeItem!, 0)
//
//f_msj(string(il_nodo),4)
end event

